package com.neusoft.chenhanhua.d0915;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ButtonGroup;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.event.ChangeEvent;

public class CanvasFrame extends JFrame implements ActionListener{
	private CanvasPanel canvas;
	public CanvasFrame() {
		setSize(450, 550);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		setTitle("东软画图软件");
		// 居中显示
		setLocationRelativeTo(null);
		//设置布局管理器
		setLayout(new BorderLayout());
		//创建按钮面板
		JPanel pBtns=new JPanel(new FlowLayout());
		//ButtonGroup单选框的
		ButtonGroup bg=new ButtonGroup();
		//第一个按钮,直线
		JRadioButton rb=new JRadioButton("直线");
		rb.setActionCommand("l");
		rb.addActionListener(this);
		bg.add(rb);
		pBtns.add(rb);
		//第二个按钮,矩形
		rb=new JRadioButton("矩形");
		rb.setActionCommand("s");
		rb.addActionListener(this);
		bg.add(rb);
		pBtns.add(rb);
		//第二个按钮,矩形
			rb=new JRadioButton("圆");
			rb.setActionCommand("c");
			rb.addActionListener(this);
			//把它加到单选框即可
			bg.add(rb);
			//加到面板
			pBtns.add(rb);
		//把按钮加到面板的上方
		add(pBtns,BorderLayout.NORTH);
		//画图面板
		canvas =new CanvasPanel();
		add(canvas,BorderLayout.CENTER);
		setVisible(true);
	}
	@Override
	public void actionPerformed(ActionEvent e) {

		String command=e.getActionCommand();
		//获取点击时的command 
		canvas.setType(command);
//		switch (command) {
//		case "l":
//			System.out.println("直线");
//			break;
//		case "s":
//			System.out.println("矩形");
//			break;
//		default:
//			break;
//		}
	}
	public static void main(String[] args) {
		new CanvasFrame();
	}

}
